/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package mobile;

import javax.ejb.Stateful;
import javax.ejb.LocalBean;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;

/**
 *
 * @author dingnangen
 */
@Stateful
@LocalBean
public class MobileloginEJB {
int i = 0;
Subject subject ;
    // Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Business Method")
    /**
     * Creates a new instance of MobileLogin
     *
     * @param username
     * @param password
     * @return
     */
    public boolean MobileLogin(String username, String password) {
        subject = SecurityUtils.getSubject();
      UsernamePasswordToken token;
    boolean loginsuccess;
    

    
        try {

            username = username.trim();
        password = password.trim();
        token = new UsernamePasswordToken(username, password);

        subject = SecurityUtils.getSubject();
        subject.login(token);
        System.out.println("loginsuccess" + i++);
        loginsuccess = true;

    }
    catch (Exception e

    
        ) {
            System.out.println("loginfail" + i++);
        loginsuccess = false;

    }
    return loginsuccess ;
}

    public Subject getSubject() {
        return subject;
    }

    public void setSubject(Subject subject) {
        this.subject = subject;
    }
}
